#e
#Title[ԁuÑ̐Hlԁv]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

let Norma=5;//Be̐ݒ
let SpellTimer=9000;//Ԃ̐ݒit[Pʁj
let StepUp=[1,2,3,4];//iKڍs閇ݒi܂܂Őݒ\jBStepUp1`5ibooleanj܂łA͖BtrueɂȂ

#include_function ".\..\txt/data.txt"

    let imgBoss =GetCurrentScriptDirectory ~ "..\lib/dot_yuka.png"; 

    // ʒu
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 112;


   @Initialize {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,5,123,277,149);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
        yield;
    }

    @DrawLoop {
	DrawBoss( imgBoss );
    }

    @Finalize {
        DeleteGraphic(imgBoss);
	FinalizeDoubleSpoiler;
    }
	@BackGround
	{

	}

    // C^XN
task TMain 
{
	yield;
	standBy;
	step;
	Shot;
}

sub standBy//ʒu
{
	SetAction(ACT_MOVE, 30);
	let wIni = 30;
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni);
	wait(wIni);
}


let AngleStart=3;
let AngleEnd=3;
let AngleRange=270;

task step
{
	while(!StepUp1){yield;}
	AngleStart=4;
	AngleEnd=5;
	while(!StepUp2){yield;}
	AngleStart=5;
	AngleEnd=6;
	AngleRange=300;
	while(!StepUp3){yield;}
	AngleStart=6;
	AngleEnd=7;
	AngleRange=330;
	while(!StepUp4){yield;}
	AngleStart=7;
	AngleEnd=8;
	AngleRange=360;
}

task Shot
{
let angle=0;
let angleplus=100;
	loop
	{
		ascent(let i in -AngleStart..AngleEnd)
		{
			BunCreateShot01(GetX, GetY,1.5,angle+GetAngleToPlayer+180+(AngleRange/(AngleStart+AngleEnd))*i,GetAngleToPlayer,15,5);
		}
			wait(10);
			angle=30*cos(angleplus);
			angleplus+=10;
	}
}

task CreateFlower(let x,let y,let angle,let angle2)
{
let speed=0.5;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
//	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, 9);
	ObjShot_SetDelay(obj, 10);
	//ObjShot_SetBombResist(obj,true);

	Obj_SetAutoDelete(obj,false);
	let X=Obj_GetX(obj);//t[WL^邽߂̒l
	let Y=Obj_GetY(obj);//t[WL^邽߂̒l
	let VanishJudg=false;//ʊOɂď𔻒B
	let aspeed=0;
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetPosition(obj, Obj_GetX(obj)+speed*cos(angle)+aspeed*cos(angle2), Obj_GetY(obj)+speed*sin(angle)+aspeed*sin(angle2));
		aspeed+=0.01;	

		if(Obj_GetX(obj)<GetClipMinX-64)//[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetX(obj)>GetClipMaxX+64)//E[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)<GetClipMinY-128)//[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)>GetClipMaxY+64)//[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		wait(1);
	}
	if(VanishJudg==false)
	{
		if(DistanceToPlayer(X,Y)<=50)
		{
			RiskShot(80);
		}
		if(DistanceToBoss(X,Y)<=50)
		{
			ClearShot;
		}
		BasePoint(80);
		BulletColor("RED");
	}
}

task BunCreateShot01(let x,let y,let speed,let angle,let angle2, let graphic,let delay)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
//	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	//ObjShot_SetBombResist(obj,true);

	Obj_SetAutoDelete(obj,false);
	let X=Obj_GetX(obj);//t[WL^邽߂̒l
	let Y=Obj_GetY(obj);//t[WL^邽߂̒l
	let VanishJudg=false;//ʊOɂď𔻒B
	let aspeed=0;
	let count=0;
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetPosition(obj, Obj_GetX(obj)+speed*cos(angle)+aspeed*cos(angle2), Obj_GetY(obj)+speed*sin(angle)+aspeed*sin(angle2));
		aspeed+=0.02;	
		if(count>=90)
		{
			graphic=12;
			ObjShot_SetGraphic(obj, graphic);
		}
		if(DistanceToPlayer(X,Y)<=50 && count>=90)
		{
		let FlowerAngle=atan2(GetPlayerY-Y,GetPlayerX-X);
		loop(3)
		{
			ascent(let i in -1..2)
			{
			CreateFlower(X,Y,FlowerAngle+i*30,FlowerAngle);
			}
		wait(3);
		}
			Obj_Delete(obj);
		}
		count+=1;
		if(Obj_GetX(obj)<GetClipMinX-64)//[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetX(obj)>GetClipMaxX+64)//E[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)<GetClipMinY-128)//[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)>GetClipMaxY+64)//[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		wait(1);
	}
	if(VanishJudg==false)
	{
		if(DistanceToPlayer(X,Y)<=50)
		{
			RiskShot(80);
		}
		if(DistanceToBoss(X,Y)<=50)
		{
			ClearShot;
		}
		BasePoint(80);
		if(graphic==15)
		{
		BulletColor("PURPLE");
		}
		if(graphic==12)
		{
		BulletColor("GREEN");
		}
	}
}

#include_function ".\..\lib/lib_anime_Patchouli.txt"
}
